import java.util.*;
class MO{
    private int No;
	private String Ontology;
	private int ns;
	private String []s=new String[10];
	private int npa;
	private int part_of[]=new int[10];
	private int nup;
	private int ndown;
	private int nup_arr[]=new int [10];
	private int uptot_arr[]=new int [10];
	private int upreal_arr[]=new int [10];
	private double upgailv_arr[]=new double [10];
	private int ndown_arr[]=new int[10];
	private int downtot_arr[]=new int[10];
	private int downreal_arr[]=new int[10];
	private double downgailv[]=new double[10];
	MO(){
		No=0;
		Ontology="";
		npa=0;
		nup=0;
		ndown=0;
	}
	public void setNo(int No){
		this.No=No;
	}
	public void setOntology(String Ontology){
		this.Ontology=Ontology;
	}
	public void setNs(int ns){
		this.ns=ns;
	}
	public void setNpa(int npa){
		this.npa=npa;
	}
	public void setNup(int nup){
		this.nup=nup;
	}
	public void setNdown(int ndown){
		this.ndown=ndown;
	}
	public void setS(String SS[]){
		for(int i=0;i<ns;i++){
			s[i]=SS[i];
		}
	}
	public void setPart_of(int PP[]){
		for(int i=0;i<npa;i++){
			part_of[i]=PP[i];
		}
	}
	public void setNup_arr(int nup_arr[]){
		for(int i=0;i<nup;i++){
			this.nup_arr[i]=nup_arr[i];
		}
	}
	public void setNdown_arr(int ndown_arr[]){
		for(int i=0;i<ndown;i++){
			this.ndown_arr[i]=ndown_arr[i];
		}
	}
	public int getNup(){
		return nup;
	}
	public int getNdown(){
		return ndown;
	}
	public int getNPup(int n){
		return nup_arr[n];
	}
	public int getNPdown(int n){
		return ndown_arr[n];
	}
	public int getNS(){
		return ns;
	}
	public int getNpa(){
		return npa;
	}
	public int getNpan(int n){
		return part_of[n];
	}
	public String getSS(){
		return s[0];
	}
	public void setUptot_arr(int []uptot_arr){
		for(int i=0;i<nup;i++){
			this.uptot_arr[i]=uptot_arr[i];
		}
	}
	public void setUpreal_arr(int []upreal_arr){
		for(int i=0;i<nup;i++){
			this.upreal_arr[i]=upreal_arr[i];
		}
	}
	public void setUpgailv_arr(){
		for(int i=0;i<nup;i++){
			this.upgailv_arr[i]=upreal_arr[i]*1.0/uptot_arr[i];
		}
	}
	public double getUpgailv(int n){
		return upgailv_arr[n];
	}
	public void Show(){
		System.out.println("编号为："+No);
		System.out.println("本体为："+Ontology);
		System.out.println("症状为:");
		for(int i=0;i<ns;i++){
			System.out.print(s[i]+" ");
		}
		System.out.println();
		System.out.println("与它有关的病症及概率为：");
		for(int i=0;i<npa;i++){
			System.out.print(part_of[i]+" ");
		}
		System.out.println();
		if(nup!=0){
			System.out.println("在它上面的关系有：");
			for(int i=0;i<nup;i++){
				System.out.print(nup_arr[i]+" "+uptot_arr[i]+" "+upreal_arr[i]+" "+upgailv_arr[i]);
			}
			System.out.println();
		}
		if(ndown!=0){
			System.out.println("在它下面的关系有：");
			for(int i=0;i<ndown;i++){
				System.out.print(ndown_arr[i]+" ");
			}
			System.out.println();
		}
		System.out.println();
	}
}

public class z11 {
	
	/**
	 * @param args
	 */
	static int dis[][]=new int[30][30];
	static int head[]=new int[30];
	static boolean isis=false;
	static double aaa[]=new double[30];
	static boolean isUsed[]=new boolean[30];
	static void dfs(int pos,MO []m,String s2,boolean isUsed[],int n){
		if(isis){
			return;
		}
		for(int i=0;i<m[pos].getNpa();i++){
			if(!isUsed[m[pos].getNpan(i)]){
				System.out.println(m[pos].getNpan(i));
				System.out.println(m[pos].getSS());
				head[n]=m[pos].getNpan(i);
				isUsed[m[pos].getNpan(i)]=true;
				if(m[m[pos].getNpan(i)].getSS().equals(s2)){
					for(int j=0;j<n;j++){
						dis[head[j]][head[j+1]]+=1;
					}
					//isis=true;
					//return ;
				}
				n++;
				dfs(m[pos].getNpan(i),m,s2,isUsed,n);
				n--;
				isUsed[m[pos].getNpan(i)]=false;
			}
			
		}
	}
	static void dfss(int pos,MO []m,String s2,int n){
		//System.out.println(pos+"   "+n);
		for(int i=0;i<m[pos].getNdown();i++){
			//System.out.println(pos+" "+m[pos].getNPdown(i));
			if(!isUsed[m[pos].getNPdown(i)]){	
				isUsed[m[pos].getNPdown(i)]=true;
				head[n]=m[pos].getNPdown(i);
				//System.out.println(m[pos].getNPdown(i)+" "+m[m[pos].getNPdown(i)].getSS());
				if(m[m[pos].getNPdown(i)].getSS().equals(s2)){
					for(int j=0;j<=n;j++){
						dis[head[j]][head[j+1]]++;
					}
					//return;
				}
				n++;
				dfss(m[pos].getNPdown(i),m,s2,n);
				n--;
				System.out.println(pos+" "+n);
				System.out.println();
				isUsed[m[pos].getNPdown(i)]=false;
			}
		}
	}
	static void dfsss(int pos,MO []m,double gv){
		for(int i=0;i<m[pos].getNup();i++){
			if(!isUsed[m[pos].getNPup(i)]){
				aaa[m[pos].getNPup(i)]+=gv*m[pos].getUpgailv(i);
				isUsed[m[pos].getNPup(i)]=true;
				dfsss(m[pos].getNPup(i),m,gv*m[pos].getUpgailv(i));
				isUsed[m[pos].getNPup(i)]=false;
			}
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String []s=new String[10];
		int part_of[]=new int [10];
		int nup[]=new int [10];
		int ndown[]=new int [10];
		int uptot_arr[]=new int [10];
		int upreal_arr[]=new int [10];
		//Queue<MO> q=new LinkedList<MO>();
		
		MO []m=new MO[30];
		for(int i=1;i<=25;i++){
			m[i]=new MO();
		}
		m[1].setNo(1);
		m[1].setOntology("科室");
		m[1].setNs(1);
		m[1].setNpa(2);
		s[0]="内科";
		part_of[0]=3;
		part_of[1]=4;
		m[1].setPart_of(part_of);
		m[1].setS(s);
		m[1].setNup(0);
		m[1].setNdown(2);
		ndown[0]=3;
		ndown[1]=4;
		uptot_arr[0]=10;
		upreal_arr[0]=3;
		uptot_arr[1]=10;
		upreal_arr[1]=2;
		m[1].setNup_arr(nup);
		m[1].setNdown_arr(ndown);
		m[1].setUptot_arr(uptot_arr);
		m[1].setUpreal_arr(upreal_arr);
		m[1].Show();
		
		
		m[2].setNo(2);
		m[2].setOntology("科室");
		m[2].setNs(1);
		m[2].setNpa(2);
		s[0]="儿科";
		part_of[0]=8;
		part_of[1]=4;
		m[2].setPart_of(part_of);
		m[2].setS(s);
		m[2].setNup(0);
		m[2].setNdown(2);
		ndown[0]=8;
		ndown[1]=4;
		m[2].setNup_arr(nup);
		m[2].setNdown_arr(ndown);
		m[2].Show();
		
		
		
		m[3].setNo(3);
		m[3].setOntology("科室");
		m[3].setNs(1);
		m[3].setNpa(6);
		s[0]="呼吸内科";
		part_of[0]=1;
		part_of[1]=9;
		part_of[2]=8;
		part_of[3]=7;
		part_of[4]=6;
		part_of[5]=5;
		m[3].setPart_of(part_of);
		m[3].setS(s);
		m[3].setNup(1);
		nup[0]=1;
		m[3].setNdown(5);
		ndown[0]=5;
		ndown[1]=6;
		ndown[2]=7;
		ndown[3]=8;
		ndown[4]=9;
		m[3].setNup_arr(nup);
		m[3].setNdown_arr(ndown);
		m[3].Show();
		
		
		
		
		m[4].setNo(4);
		m[4].setOntology("病症");
		m[4].setNs(1);
		m[4].setNpa(4);
		s[0]="传染病";
		part_of[0]=1;
		part_of[1]=2;
		part_of[2]=9;
		part_of[3]=14;
		m[4].setPart_of(part_of);
		m[4].setS(s);
		m[4].setNup(2);
		nup[0]=1;
		nup[1]=2;
		m[4].setNdown(2);
		ndown[0]=14;
		ndown[1]=9;
		m[4].setNup_arr(nup);
		m[4].setNdown_arr(ndown);
		m[4].Show();
		
		
		
		
		m[5].setNo(5);
		m[5].setOntology("病症");
		m[5].setNs(1);
		m[5].setNpa(1);
		s[0]="哮喘";
		part_of[0]=3;
		m[5].setPart_of(part_of);
		m[5].setS(s);
		m[5].setNup(1);
		nup[0]=3;
		m[5].setNdown(0);
		m[5].setNup_arr(nup);
		m[5].setNdown_arr(ndown);
		m[5].Show();
		
		
		
		
		m[6].setNo(6);
		m[6].setOntology("病症");
		m[6].setNs(1);
		m[6].setNpa(3);
		s[0]="感冒";
		part_of[0]=3;
		part_of[1]=10;
		part_of[2]=11;
		m[6].setPart_of(part_of);
		m[6].setS(s);
		m[6].setNup(1);
		nup[0]=3;
		m[6].setNdown(2);
		ndown[0]=10;
		ndown[1]=11;
		m[6].setNup_arr(nup);
		m[6].setNdown_arr(ndown);
		m[6].Show();
		
		
		//m[16]=new MO();
		m[7].setNo(7);
		m[7].setOntology("器官");
		m[7].setNs(1);
		m[7].setNpa(1);
		s[0]="支气管";
		part_of[0]=3;
		m[7].setPart_of(part_of);
		m[7].setS(s);
		m[7].setNup(1);
		nup[0]=3;
		m[7].setNdown(0);
		m[7].setNup_arr(nup);
		m[7].setNdown_arr(ndown);
		m[7].Show();
		
		
		
		m[8].setNo(8);
		m[8].setOntology("器官");
		m[8].setNs(1);
		m[8].setNpa(5);
		s[0]="肺";
		part_of[0]=3;
		part_of[1]=2;
		part_of[2]=12;
		part_of[3]=13;
		part_of[4]=14;
		m[8].setPart_of(part_of);
		m[8].setS(s);
		m[8].setNup(2);
		nup[0]=3;
		nup[1]=2;
		m[8].setNdown(3);
		ndown[0]=12;
		ndown[1]=13;
		ndown[2]=14;
		m[8].setNup_arr(nup);
		m[8].setNdown_arr(ndown);
		m[8].Show();
		
		
		
		m[9].setNo(9);
		m[9].setOntology("病症");
		m[9].setNs(1);
		m[9].setNpa(3);
		s[0]="流感";
		part_of[0]=3;
		part_of[1]=4;
		part_of[2]=15;
		m[9].setPart_of(part_of);
		m[9].setS(s);
		m[9].setNup(2);
		nup[0]=1;
		nup[1]=2;
		m[9].setNdown(1);
		ndown[0]=15;
		m[9].setNup_arr(nup);
		m[9].setNdown_arr(ndown);
		m[9].Show();
		
		//m[8]=new MO();
		m[10].setNo(10);
		m[10].setOntology("病症");
		m[10].setNs(1);
		m[10].setNpa(5);
		s[0]="病毒感冒";
		part_of[0]=6;
		part_of[1]=18;
		part_of[2]=19;
		part_of[3]=20;
		part_of[4]=21;
		m[10].setPart_of(part_of);
		m[10].setS(s);
		m[10].setNup(1);
		nup[0]=6;
		m[10].setNdown(4);
		ndown[0]=18;
		ndown[1]=19;
		ndown[2]=20;
		ndown[3]=21;
		m[10].setNup_arr(nup);
		m[10].setNdown_arr(ndown);
		m[10].Show();
		
		
		//m[9]=new MO();
		m[11].setNo(11);
		m[11].setOntology("病症");
		m[11].setNs(1);
		m[11].setNpa(1);
		s[0]="伤寒";
		part_of[0]=6;
		m[11].setPart_of(part_of);
		m[11].setS(s);
		m[11].setNup(1);
		nup[0]=6;
		m[11].setNdown(0);
		m[11].setNup_arr(nup);
		m[11].setNdown_arr(ndown);
		m[11].Show();
		
		//m[10]=new MO();
		m[12].setNo(12);
		m[12].setOntology("病症");
		m[12].setNs(1);
		m[12].setNpa(4);
		s[0]="肺炎";
		part_of[0]=16;
		part_of[1]=19;
		part_of[2]=17;
		part_of[3]=8;
		m[12].setPart_of(part_of);
		m[12].setS(s);
		m[12].setNup(1);
		nup[0]=8;
		m[12].setNdown(3);
		ndown[0]=16;
		ndown[1]=17;
		ndown[2]=19;
		m[12].setNup_arr(nup);
		m[12].setNdown_arr(ndown);
		m[12].Show();
		
		
		//m[11]=new MO();
		m[13].setNo(13);
		m[13].setOntology("病症");
		m[13].setNs(1);
		m[13].setNpa(2);
		s[0]="肺癌";
		part_of[0]=21;
		part_of[1]=25;
		m[13].setPart_of(part_of);
		m[13].setS(s);
		m[13].setNup(1);
		nup[0]=8;
		m[13].setNdown(2);
		ndown[0]=21;
		ndown[1]=25;
		m[13].setNup_arr(nup);
		m[13].setNdown_arr(ndown);
		m[13].Show();
		
		
		//m[12]=new MO();
		m[14].setNo(14);
		m[14].setOntology("病症");
		m[14].setNs(1);
		m[14].setNpa(3);
		s[0]="肺结核";
		part_of[0]=4;
		part_of[1]=8;
		part_of[2]=21;
		m[14].setPart_of(part_of);
		m[14].setS(s);
		m[14].setNup(2);
		nup[0]=8;
		nup[1]=4;
		m[14].setNdown(1);
		ndown[0]=21;
		m[14].setNup_arr(nup);
		m[14].setNdown_arr(ndown);
		m[14].Show();
		
		
		
		m[15].setNo(15);
		m[15].setOntology("病症");
		m[15].setNs(1);
		m[15].setNpa(1);
		s[0]="H1N1";
		part_of[0]=9;
		m[15].setPart_of(part_of);
		m[15].setS(s);
		m[15].setNup(1);
		nup[0]=9;
		m[15].setNdown(0);
		m[15].setNup_arr(nup);
		m[15].setNdown_arr(ndown);
		m[15].Show();
		
		
		
		
		m[16].setNo(16);
		m[16].setOntology("病症");
		m[16].setNs(1);
		m[16].setNpa(4);
		s[0]="新生儿肺炎";
		part_of[0]=18;
		part_of[1]=19;
		part_of[2]=21;
		part_of[3]=12;
		m[16].setPart_of(part_of);
		m[16].setS(s);
		m[16].setNup(1);
		nup[0]=12;
		m[16].setNdown(3);
		ndown[0]=18;
		ndown[1]=19;
		ndown[2]=21;
		m[16].setNup_arr(nup);
		m[16].setNdown_arr(ndown);
		m[16].Show();
		
		//m[7]=new MO();
		m[17].setNo(17);
		m[17].setOntology("病症");
		m[17].setNs(1);
		m[17].setNpa(3);
		s[0]="肺气肿";
		part_of[0]=19;
		part_of[1]=21;
		part_of[2]=12;
		m[17].setPart_of(part_of);
		m[17].setS(s);
		m[17].setNup(1);
		nup[0]=12;
		m[17].setNdown(2);
		ndown[0]=19;
		ndown[1]=21;
		m[17].setNup_arr(nup);
		m[17].setNdown_arr(ndown);
		m[17].Show();
		
		
		
		m[18].setNo(18);
		m[18].setOntology("病症");
		m[18].setNs(1);
		m[18].setNpa(4);
		s[0]="发烧";
		part_of[0]=22;
		part_of[1]=23;
		part_of[2]=10;
		part_of[3]=16;
		m[18].setPart_of(part_of);
		m[18].setS(s);
		m[18].setNup(2);
		nup[0]=1;
		nup[1]=2;
		m[18].setNdown(2);
		ndown[0]=22;
		ndown[1]=23;
		m[18].setNup_arr(nup);
		m[18].setNdown_arr(ndown);
		m[18].Show();
		
		//m[3]=new MO();
		m[19].setNo(19);
		m[19].setOntology("病症");
		m[19].setNs(1);
		s[0]="咳嗽";
		m[19].setS(s);
		m[19].setNpa(4);
		part_of[0]=10;
		part_of[1]=16;
		part_of[2]=17;
		part_of[3]=12;
		m[19].setPart_of(part_of);
		m[19].setNup(4);
		nup[0]=10;
		nup[1]=16;
		nup[2]=12;
		nup[3]=17;
		m[19].setNdown(0);
		m[19].setNup_arr(nup);
		m[19].setNdown_arr(ndown);
		m[19].Show();
		
		//m[4]=new MO();
		m[20].setNo(20);
		m[20].setOntology("症状");
		m[20].setNs(1);
		s[0]="头疼";
		m[20].setS(s);
		part_of[0]=10;
		m[20].setNpa(1);
		m[20].setPart_of(part_of);
		m[20].setNup(1);
		nup[0]=10;
		m[20].setNdown(0);
		m[20].setNup_arr(nup);
		m[20].setNdown_arr(ndown);
		m[20].Show();
		
		//m[5]=new MO();
		m[21].setNo(21);
		m[21].setOntology("症状");
		m[21].setNpa(7);
		m[21].setNs(1);
		s[0]="有痰";
		m[21].setS(s);
		part_of[5]=24;
		part_of[6]=25;
		part_of[0]=10;
		part_of[1]=16;
		part_of[2]=17;
		part_of[3]=13;
		part_of[4]=14;	
		m[21].setPart_of(part_of);		
		m[21].setNup(5);
		nup[0]=10;
		nup[1]=16;
		nup[2]=13;
		nup[3]=14;
		m[21].setNdown(2);
		ndown[0]=24;
		ndown[1]=25;
		m[21].setNup_arr(nup);
		m[21].setNdown_arr(ndown);
		m[21].Show();
		
		
		m[22].setNo(22);
		m[22].setOntology("病症");
		m[22].setNs(2);
		m[22].setNpa(1);
		s[0]="高烧";
		s[1]="体温上升";
		part_of[0]=18;
		m[22].setPart_of(part_of);
		m[22].setS(s);
		m[22].setNup(1);
		nup[0]=18;
		m[22].setNdown(0);
		m[22].setNup_arr(nup);
		m[22].setNdown_arr(ndown);
		m[22].Show();
		
		
		m[23].setNo(23);
		m[23].setOntology("病症");
		m[23].setNs(1);
		m[23].setNpa(1);
		s[0]="低烧";
		part_of[0]=18;
		m[23].setPart_of(part_of);
		m[23].setS(s);
		m[23].setNup(1);
		nup[0]=18;
		m[23].setNdown(0);
		m[23].setNup_arr(nup);
		m[23].setNdown_arr(ndown);
		m[23].Show();
		
		
		m[24].setNo(24);
		m[24].setOntology("病症");
		m[24].setNs(1);
		m[24].setNpa(1);
		s[0]="黄痰";
		part_of[0]=21;
		m[24].setPart_of(part_of);
		m[24].setS(s);
		m[24].setNup(1);
		nup[0]=21;
		m[24].setNdown(0);
		m[24].setNup_arr(nup);
		m[24].setNdown_arr(ndown);
		m[24].Show();
		
		m[25].setNo(25);
		m[25].setOntology("病症");
		m[25].setNs(1);
		m[25].setNpa(2);
		s[0]="痰中带血";
		part_of[0]=21;
		part_of[1]=13;
		m[25].setPart_of(part_of);
		m[25].setS(s);
		m[25].setNup(2);
		nup[0]=13;
		nup[1]=21;
		m[25].setNdown(0);
		m[25].setNup_arr(nup);
		m[25].setNdown_arr(ndown);
		m[25].Show();
		
		//for(int i=1;i<=25;i++){
		//	m[i].Show();
		//}
		//System.out.println(m[20].getSS());
		String s1="肺";
		String s2="黄痰";
		int pos = 0;
		for(int i=1;i<=25;i++){
			if(s1.equals(m[i].getSS())){
				pos=i;break;
			}
		}
		
		for(int i=1;i<=25;i++){
			for(int j=1;j<=25;j++){
				dis[i][j]=0;
			}
		}
		
		
		for(int i=1;i<=25;i++){
			isUsed[i]=false;
			aaa[i]=0;
		}
		head[0]=pos;
		System.out.println(pos+" "+"yyy");
		int n=1;
		
		dfss(pos,m,s2,n);
		for(int i=1;i<=25;i++){
			for(int j=1;j<=25;j++){
				System.out.print(dis[i][j]+" ");
			}
			System.out.println();
		}
	}

}
